<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.net.*"%>
<%@ page import="org.json.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.el.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.config.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.tree.*"%>
<%@ page import="com.gzgi.framework.dataitem.*"%>
<%@ page import="com.gzgi.framework.sys.*"%>
<%@ page import="com.gzgi.framework.sys.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.container.*"%>
<%@ page import="org.apache.commons.lang.*"%>
<%@ page import="org.apache.commons.httpclient.*" %>
<%@ page import="org.apache.commons.httpclient.methods.*" %>
<%@ page import="org.apache.commons.httpclient.params.*" %>
<%
    String activationCode = request.getParameter("xyz_activationCode");
	String redirectUrl = request.getParameter("redirectUrl");
    UserService userService = (UserService)ContextFactory.getBean("userService");
    User user = userService.getUserByActivationCode(activationCode);
	if (user != null) {
		SecurityContext securityContext = new SecurityContext();
		securityContext.setActorId(user.getActorId());
		user.setLastLoginDate(new Date());
		user.setLoginIP(request.getRemoteAddr());
		user.setLoginRetry(0);
		securityContext.setUser(user);
		request.getSession().setAttribute(SecurityContext.LOGIN_ACTOR_ID,	user.getActorId());
		request.getSession().setAttribute(SecurityContext.SECURITY_CONTEXT, securityContext);
		if (StringUtils.isNotEmpty(redirectUrl)) {
				redirectUrl = RequestUtil.decodeURL(redirectUrl);
				if (!redirectUrl.startsWith(request.getContextPath())) {
					redirectUrl = request.getContextPath() + redirectUrl;
				}
		        response.sendRedirect(redirectUrl);	 
		}
	}
%>